package com.java.prittern.singleton;
//双检锁/双重校验锁（DCL，即double-checked locking）
//jdk1.5起，线程安全，较复杂
//这种方式采用双锁机制，安全且在多线程情况下保持高性能
//getInstance()的性能对应用程序很关键
public class Singleton4 {
    private volatile static Singleton4 singleton4;

    private Singleton4() {
    }
    public static Singleton4 getInstance(){
        if (singleton4==null){
            synchronized (Singleton4.class){
                if (singleton4==null){
                    singleton4=new Singleton4();
                }
            }
        }
        return singleton4;
    }
}
